﻿using System.Text;
using Microsoft.AspNetCore.Http;

namespace K9Nano.Extensions;

public static class HttpResponseExtensions
{
    public static async Task WriteAsUtf8Async(this HttpResponse response,
        string content,
        int statusCode = StatusCodes.Status200OK,
        CancellationToken cancellation = default)
    {
        response.ContentType = "text/plain; charset=utf-8";
        response.StatusCode = statusCode;
        await response.WriteAsync(content, Encoding.UTF8, cancellation);
        await response.CompleteAsync();
    }
}
